import * as newFetch from 'ofetch'
export default defineNuxtPlugin((nuxtApp) => {
  const config = useRuntimeConfig().public
  let baseURL = config.API_URL + '/api'
  if (process.client) {
    baseURL = `${location.origin}/api`
  } else {
    baseURL = config.API_URL + '/api'
  }
  const fetchOptions = {
    baseURL,
  }
  const apiFetch = newFetch.$fetch.create(fetchOptions)

  return {
    provide: {
      apiFetch,
    },
  }
})
